home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
- #include "procbox.h"
- #include "papp4res.h" // resource includes
-
-
- int CALLBACK _export PBCallback(HWND, int , LPARAM);
- BOOL CALLBACK _export PBDlgProc(HWND, UINT, WPARAM, LPARAM);
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // PROCAPP4.C - Demonstrates use of Custom Process Box Interface
- //
- // - This demo shows how to make a simple Single-Callback
- // Modal Custom Process Box.
- //
- // - To use Custom Process Box with multiple callbacks or
- // as a modeless dialog (using the low-level interface),
- // you should look at PROCAPP2.C and PROCAPP3.C.
- // (Replace calls to CreateProcessBox with
- // CreateCustomProcessBox.)
- //
- // - Contains code for
- // - WinMain Entry Point
- // - WndProc
-
- LRESULT FAR PASCAL _export WndProc(HWND, UINT, WPARAM, LPARAM);
-
-
- char szAppName[] = "PROCAPP4";
- char szWindowText[] = "ProcessBox - Modal Custom Process Box Demo";
-
-
- /////////////////////////////////////////////////
- //
- //
- // WndProc
- //
-
- LRESULT FAR PASCAL _export WndProc (HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- FARPROC lpfnPBCallback;
- FARPROC lpfnPBDlgProc;
- char szText[64];
- HINSTANCE hinst;
-
- switch (message)
- {
- case WM_KEYDOWN:
- case WM_LBUTTONDOWN:
- hinst = GetWindowWord(hwnd, GWW_HINSTANCE);
- lpfnPBCallback = MakeProcInstance((FARPROC)PBCallback, hinst);
- lpfnPBDlgProc = MakeProcInstance((FARPROC)PBDlgProc, hinst);
-
- wsprintf(szText, "Returned: %d",
- CustomProcessBox(hinst,
- MAKEINTRESOURCE(IDD_CUSTPROCBOX),
- hwnd,
- lpfnPBDlgProc,
- lpfnPBCallback,
- NULL)); // user data
-
- MessageBox(hwnd, szText, NULL, NULL);
-
- FreeProcInstance(lpfnPBCallback); // free the callback thunk
- FreeProcInstance(lpfnPBDlgProc); // free the dialog box thunk
- return 0;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc (hwnd, message, wParam, lParam );
- }
- ///////////////////////////////////////////////////////////
- //
- // The Custom Process Box Dialog Callback Procedure
- //
- //
- //
- BOOL CALLBACK _export PBDlgProc(HWND hwndPB, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return TRUE;
-
- case WM_COMMAND:
- switch (wParam)
- {
- case IDC_STOPPROCESS:
- SetCancelState(hwndPB, TRUE); // stop the process. This will kill destroy this dialog.
- return 0;
- }
- return 0;
-
- case PM_SETGAUGE:
- SetDlgItemInt(hwndPB, IDC_PERCENT, wParam, FALSE);
- return 0;
- }
- return 0;
-
- }
- ///////////////////////////////////////////////////////////
- //
- // The Process Box Callback
- //
- //
- int CALLBACK _export PBCallback(HWND hwndPB, int iCode, LPARAM lParam)
- {
- static int i;
- int iPercent;
- static int iPercentOld;
- long j;
-
- switch (iCode)
- {
- case PBC_OPEN:
- // allocate memory here
- i=0;
- return TRUE;
-
- case PBC_CLOSE:
- // free memory here
- return TRUE;
-
- case PBC_CANCEL:
- return ( MessageBox(hwndPB, "Really cancel operation?", "Message Box",
- MB_APPLMODAL|MB_YESNO)==IDYES ? TRUE : FALSE );
-
-
- case PBC_PROCESS:
- for (j=0; j<0xEFF; j++); // processing !
- i++;
-
- if (i>10000)
- return PBCR_END;
-
- if (i==5000)
- SetWindowText(hwndPB, "Reached halfway");
-
- iPercent = i/100;
-
- if (iPercent != iPercentOld)
- {
- iPercentOld = iPercent;
- SendMessage(hwndPB, PM_SETGAUGE, iPercent, 0l);
- }
- return PBCR_CONTINUE;
-
- }
- return TRUE;
- }
-
- /////////////////////////////////////////////////
- //
- //
- // WinMain - Entry Point
- //
- //
- int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow)
- {
-
- MSG msg ;
- WNDCLASS wndclass ;
- HWND hwnd;
-
- if (!hPrevInstance)
- {
- wndclass.style = NULL ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName = szAppName ;
-
- RegisterClass (&wndclass) ;
- }
-
- hwnd = CreateWindow ( szAppName, // class
- szWindowText, // window text
- WS_OVERLAPPEDWINDOW, // style
- CW_USEDEFAULT, CW_USEDEFAULT, // x, y start
- CW_USEDEFAULT, CW_USEDEFAULT, // width, height
- NULL, // parent window handle
- NULL, // menu handle
- hInstance, // instance handle
- NULL) ; // long pointer to creation data
-
- ShowWindow (hwnd, nCmdShow) ;
- UpdateWindow (hwnd) ;
-
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
-
- return msg.wParam ;
- }
-